<template>
  <div>
    <home-header :list="city"></home-header>
    <home-swiper :swiperList="swiperList"></home-swiper>
    <home-icons :iconList="iconList"></home-icons>
    <recommend :recommendList="recommendList"></recommend>
    <weekend :weekendList="weekendList"></weekend>
  </div>
</template>

<script>

import HomeHeader from './components/Header'
import homeSwiper from './components/Swiper'
import HomeIcons from './components/HomeIcons'
import recommend from './components/Recommend'
import weekend from './components/Weekend'
import axios from 'axios'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    homeSwiper,
    HomeIcons,
    recommend,
    weekend,
  },
  data() {
    return {
      city: [],
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
    };
  },
  methods: {
    getCityInfo() {
      axios.get('/api/city.json')
        .then(this.setCityInfos)
    },
    getHomeInfo() {
      axios.get('/api/index.json')
        .then(this.getHomeInfos)
    },
    getHomeInfos(res) {
      res = res.data;
      if(res.data && res.ret) {
        this.swiperList = res.data.swiperList;
        this.iconList = res.data.iconList;
        this.recommendList = res.data.recommendList;
        this.weekendList = res.data.weekendList;
      }
    },
    setCityInfos(res) {
      //console.log(res);
      res = res.data;
      if(res.data && res.ret) {
        this.city = res.data.hotCities;
      }
    },
  },
  mounted() {
    this.getHomeInfo(),
    this.getCityInfo();
  },
};
</script>

<style>
  .home {
    font-size: 30px;
  }
</style>
